/*
 * PlaylistInsertAction.java
 *
 * Created on April 8, 2006, 1:28 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
package com.bff.slimserver.musicjukebox.lib.actions;

import com.bff.slimserver.musicjukebox.lib.JukeboxProperties;
import com.bff.slimserver.musicjukebox.ui.SplashScreen;
import com.bff.bjj.utils.Resources;
import java.awt.event.ActionEvent;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JFrame;
import org.bff.slimserver.exception.SlimConnectionException;
import org.bff.slimserver.exception.SlimNetworkException;
import org.bff.slimserver.musicobjects.radio.SlimRadioAudioDetails;
import org.bff.slimserver.musicobjects.radio.SlimRadioItem;

/**
 *
 * @author Bill
 */
public class ViewRadioAction extends AbstractAction {

    private SlimRadioItem item;
    private JFrame parent;
    private SplashScreen sp;

    /** Creates a new instance of PlaylistInsertAction */
    public ViewRadioAction(JFrame parent, SlimRadioItem item) {
        this.item = item;
        this.parent = parent;
        putValue(Action.NAME, Resources.getMessage(Resources.LABEL_KEY.ACTION_VIEW_RADIO_NAME));
        putValue(Action.SHORT_DESCRIPTION, Resources.getMessage(Resources.LABEL_KEY.ACTION_VIEW_RADIO_SHORT_DESC));
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        sp = new SplashScreen(parent, true);
        sp.setIndeterminate(true);
        sp.setTitleLabel(Resources.getMessage(Resources.LABEL_KEY.RADIO_LOADING_TITLE));
        sp.setMainTextArea(Resources.getMessage(Resources.LABEL_KEY.RADIO_LOADING_TEXT, new Object[]{item}));
        sp.setProgressBarLabel(Resources.getMessage(Resources.LABEL_KEY.RADIO_LOADING_PROGRESS_BAR));
        sp.pack();

        new Thread(new Runnable() {

            @Override
            public void run() {
                SlimRadioAudioDetails radioDetails = null;
                try {
                    radioDetails = JukeboxProperties.getInstance().getRadioPlugin().getAudioDetails(item, JukeboxProperties.getInstance().getPlayer());
                } catch (SlimConnectionException ex) {
                    Logger.getLogger(ViewRadioAction.class.getName()).log(Level.SEVERE, null, ex);
                } catch (SlimNetworkException ex) {
                    Logger.getLogger(ViewRadioAction.class.getName()).log(Level.SEVERE, null, ex);
                } finally {
                    sp.setVisible(false);
                }
            }
        }).start();
    }
}
